<template>
	<view>
	    <view class="saoyisao">
	       <view class="soyiso" @click="saoyisao" v-if="isclick == 0">扫码签收</view>
	    </view>
	    <view class="tips">
	        <view class="texttips">温馨提示：同一个发货单,只扫一箱</view>
	        <view class="">或者一罐就可以整批入库，无需全部扫。</view>
	        <view class="">如：货品数量不对时，可以拒绝收货。</view>
	    </view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				order_no:"",
				city:"",
				province:"",
				nation:"",
				isclick:0,
				latitude:"",
				longitude:""
			}
		},
		onShow(){ },
		onLoad(p) {
		   if(p.order_no){
			   this.order_no=p.order_no
		   }
		   this.getAddress()
		},
		methods: {
			 //调用扫一扫
			saoyisao(){
			  var that=this
			  uni.scanCode({
				  success: (res) => {
					  if(res.errMsg=='scanCode:ok'){
						  var result = res.result
						  that.get_check_boxcode(result);
					  }else{
						  uni.showToast({  title: '未识别到任何数据！', icon:"none" })
					  }
				  }
			  })
			},
			getAddress: function() {
				var n = this;
				uni.getLocation({
					type: 'wgs84',
					success: function(e) {
						var d={}
						d.latitude=e.latitude
						d.longitude=e.longitude
						uni.setStorageSync('latitude', e.latitude)
						uni.setStorageSync('longitude', e.longitude)
						n.latitude=e.latitude
						n.longitude=e.longitude
						n.request('/api/code/get_city', d,"post").then(ret => {
							n.city=ret.info.result.address_component.district
							n.province=ret.info.result.address_component.province
							n.nation=ret.info.result.address_component.nation
						})
					},
					fail: (res) => {
						console.log(res)
						if(res.errno==103){
							uni.showModal({
							  title: '提示',
							  content:"请手动开启定位，点击顶部三点-设置开启"
							})
						}else if(res.errno==104){
							uni.navigateTo({
							  url: '/pages/login/login',
							})
						}
						else{
							if(res.errCode == 2){
								uni.showModal({
									title: '提示',
									showCancel:false,
									content:"请先开启定位"
								  })
							}else if(res.errCode == 1){
							  uni.showModal({
								  title: '提示',
								  showCancel:false,
								  content:"请关闭WIFI并开启定位"
								})
							}else if(res.errCode == -1){
							  uni.showModal({
								  title: '提示',
								  showCancel:false,
								  content:"请开启手机定位"
								})
							}
							else{
								uni.showModal({
									title:"提示",
									showCancel:false,
									content: "错误码:"+JSON.stringify(res),
								})
							}
						}
					}
				});
			 },
			//请求扫码签收
			get_check_boxcode(boxcode){
			  var data={}
			  var that=this;
			  data.code=boxcode
			  data.order_no=that.order_no
			  data.jxs_code=uni.getStorageSync('fahuo_username').user_code
			  data.system_user=uni.getStorageSync('fahuo_username').id
			  data.latitude=that.latitude
			  data.longitude=that.longitude
			  data.city=that.city
			  data.province=that.province
			  data.nation=that.nation
			  if(this.isclick == 1){
				  uni.showToast({
				  	title:"请勿重复扫码",
					icon:"none"
				  })
				  return;
			  }
			  this.isclick=1;
			  uni.showLoading({
			  	title:"请求中...请稍后"
			  })
			  this.request('/api/duoqudao/saoma_shouhuo_order', data,"post").then(ret => {
				    uni.hideLoading();
					uni.showModal({
						title: '温馨提示',
						content:ret.message,
						showCancel:false,
						success:function(){ uni.navigateBack({delta:2}) }
					})
			  })
			}
		}
	}
</script>

<style>
.saoyisao{
  margin: 20px auto;
  width: 100%;
  text-align: center;
  text-align: center;
  

  color: #fff;
  height: 45px;
  line-height: 45px;
  margin-top: 60%;
  font-size: 18px;
}
.showdata{
  display: flex;
  position: relative;
  top: 20px;
}
.itemvv{
    width: 33%;
    text-align: center;
    display: inline-table;
    border: 1px solid #1B764A;
}
.tips{
  width: 100%;
  text-align: center;
  color: #272727;
  font-size: 14px;
  position: absolute;
  bottom: 100px;
}
.texttips22{
  position: relative;
  top:25px;
}
.showhistdata{
  width: 100%;
  height: 100px;
  overflow: auto;
  position: relative;
  top: 20px;
}
.f14{
  font-size: 15px;
}
.soyiso{
  width: 60%;
  background-color: #1B764A;
  border-radius: 20px;
  margin: 10px auto;
  letter-spacing: 10px;
}
.tips2{
  width: 100%;
  text-align: center;
  color: #000;
  font-size: 14px;
}
.chexiaobtn{
  color: red;
  font-size: 16px;
  padding-top: 15px;
}
.saomingx{
  color: #1B764A;
  font-size: 16px;
}
page{
  background: url('https://ayh.wissun.net/static/ayh/bg.jpg?1');
  background-size: 100% 100%;
}
</style>
